package me.hys.api.doctor;

import java.util.List;

import me.hys.api.BaseApi;
import me.hys.base.ApiResult;
import me.hys.base.PageQuery;
import me.hys.bo.doctor.ReservationBo;
import me.hys.bo.doctor.RvtUserBo;
import me.hys.entity.doctor.ReservationEntity;
import me.hys.service.doctor.IDoctorManager;
import me.hys.service.doctor.IReservationManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Author: @author HYS . <br>
 * Date: 2015-9-22 上午12:34:13 . <br>
 * Function: 预约API
 */
@Controller
@RequestMapping("/api/rvt")
public class ReservationApi extends BaseApi {
	@Autowired
	private IDoctorManager doctorManager;
	@Autowired
	private IReservationManager reservationManager;

	/**
	 * @Title : getReservation
	 * @Description : 获取医生可预约时间段
	 */
	@ResponseBody
	@RequestMapping(value = "/get_time/{userid}", method = RequestMethod.GET)
	public ReservationBo getReservation(@PathVariable String userid) {
		return doctorManager.findReservation(userid);
	}

	/**
	 * @Title : list
	 * @Description : 获取预约列表
	 */
	@ResponseBody
	@RequestMapping(value = "/list/{history}/{userid}/{start}", method = RequestMethod.GET)
	public List<RvtUserBo> list(@PathVariable String history,
			@PathVariable int userid, @PathVariable int start) {
		PageQuery<RvtUserBo> page = getPageQuery(start);
		page.getCondition().put("userid", userid);
		page.getCondition().put("history", history);
		PageQuery<RvtUserBo> result = reservationManager.findPageBo(page);
		return result.getList();
	}

	/**
	 * @Title : post
	 * @Description : 保存或者更新患者的预约信息
	 */
	@ResponseBody
	@RequestMapping(value = "/post", method = RequestMethod.POST)
	public ApiResult post(@ModelAttribute ReservationEntity entity) {
		return reservationManager.saveOrUpdate(entity);
	}

	/**
	 * @Title : postReservation
	 * @Description : 保存医生可预约时间段
	 */
	@ResponseBody
	@RequestMapping(value = "/post_time", method = RequestMethod.POST)
	public ApiResult postReservation(@RequestParam int userid,
			@ModelAttribute ReservationBo reservation) {
		reservation.setUserid(userid);
		return doctorManager.updateReservation(reservation);
	}

	/**
	 * @Title : postStatus
	 * @Description : 更新预约状态（医生）
	 */
	@ResponseBody
	@RequestMapping(value = "/post_status", method = RequestMethod.POST)
	public ApiResult postStatus(@RequestParam int id, @RequestParam int status) {
		ReservationEntity entity = new ReservationEntity();
		entity.setId(id);
		entity.setStatus(status);
		return reservationManager.saveOrUpdate(entity);
	}
}
